<template>
    <el-upload
    drag 
    :action='UploadImg'
    :headers="{
        token
    }"
    name="img"
    :data="data"
    :on-success="UploadSuccess"
    :on-error="UploadError"
    multiple>
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">
         <em>点击此处</em>
        </div>
        <template #tip>
            <div class="el-upload__tip">
                
            </div>
        </template>
    </el-upload>
</template>

<script setup>
import { UploadImg } from '~/api/image_class.js'
import {getToken} from '~/composables/auth.js'
import {success} from '~/composables/util.js'
 const token =getToken()

 const emit= defineEmits(['success'])

 //上传成功
 const UploadSuccess=(response,uploadFile,uploadFiles)=>{
    emit('success',{response,uploadFile,uploadFiles})
 }
 //上传失败
 const UploadError=(error,uploadFile,uploadFiles)=>{
    let msg=JSON.parse(error.message).mgs||'上传失败'
    success(msg,'error')
 }

 defineProps({
    data:Object
 })
</script>